/**
 * @author:albert
 */

package com.bkbw.live.database.net.codec;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.bkbw.live.common.dataproto.BattleToDatabasePb.BS2DBTableReq;
import com.bkbw.live.common.dataproto.BattleToDatabasePb.DB2BSTableResp;
import com.bkbw.live.common.dataproto.BattleToDatabasePb.HeadType;


public class PackageHead {
public static Map<Short,String> map = new HashMap<>();
	
	static{
		//通过proto文件去反射
		map.put((short)HeadType.BS2DB_TABLE_REQ_VALUE, BS2DBTableReq.class.getName());
		
		map.put((short)HeadType.DB2BS_TABLE_RESP_VALUE, DB2BSTableResp.class.getName());
		
		}
	
	/**
	 * 根据消息头来获得传输类的名字
	 * @param head
	 * @return
	 */
	public static String getClassNameByHead(short head){
		return map.get(head);
	}
	
	/**
	 * 根据类名来查找这个类应该匹配哪个消息头
	 * @param name
	 * @return
	 */
	public static short getHeadByClassName(String name){
		Iterator<Short> it = map.keySet().iterator();
		while(it.hasNext()){
			short head = it.next();
			if(map.get(head).equals(name)){
				return head;
			}
		}
		return 0;
	}
}
